<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入添加的图片数量">
<input type="button" value="帅哥" onclick="f(1)">
<input type="button" value="美女" onclick="f(2)">
<hr>
<script>
    let input = document.querySelector("input");
  function f(x) {
    //根据传递过来的x的值 得到不同的图片路径
    let url = x==1?"a.jpg":"b.jpg";
    //循环遍历添加图片, 次数和用户输入的数值一样
      for (let i = 0; i < input.value; i++) {
          let img = document.createElement("img");
          img.src = url;
          document.body.append(img);
      }

  }
</script>
</body>
</html>